/*
 * @Author: 贺楠 1071780426@qq.com
 * @Date: 2024-09-10 11:12:20
 * @LastEditors: 贺楠 1071780426@qq.com
 * @LastEditTime: 2024-09-11 10:23:18
 * @FilePath: \monitoring_system\src\components\testMachineManage\equipmentManage\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import publicForm from "@/components/public/el-forms.vue"; //弹框form
import userImage from "@/components/public/userImage-upload.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项
import {
    updateMachineException, //保存
    getMachineException, //详情

} from "@/api/abnormalDataProcessManage/request.js";
export default {
    props: [
        "dialogVisible",
        "dialogTitle",
        "statusNum",
        "currentRow",
     
    ],
    data() {
        return {
            visible: "",
            loading: false,
            title: null,
            isLock: false,
            dialogHeight: null,
            treeData: [], //材料种类
            formData: {
                fId: "",
                examineResult: "",
                reason: ""
            },
            formObj: formJs.formObj,
  
            btnShow: true,
            currentDetail: null,
            selected: [],
            typs: null,
            fileList: []
        };
    },
    components: {
        publicForm,
        userImage
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
       
        statusNum: {
            handler(newVal) {
                if (newVal) {

                    this.edit(newVal);
                }
            },
            immediate: true,
        },
        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentDetail = newVal;
                    this.getDetail({
                        fId: this.currentDetail.fId
                    })
                }
            },
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：
    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("monitorBack-userInfo"));
        this.btnShow = true

        if (this.statusNum ==13) { //审核
            this.formData.fId = this.currentDetail.fId ;//按钮 
           
            this.formObj.map((item) => {
                item.disabled = true;
            });
            this.formObj[6].disabled=false;
            this.formObj[7].disabled=false;

            this.btnShow = true
        } else if (this.statusNum == 7) { //查看
            this.btnShow = false
            this.formObj.map((item) => {
                item.disabled = true;
            });
        }
        this.getHeight();
    },
    methods: {
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.5 + "px";
        },
        handleSelect(key) {
            this.activeIndex = key;
        },
        closeDialog() {
            this.$emit("close");
        },
        // selectChange(data, a, b) {
        //     console.log(a);
        // },
        edit() {
            this.formData = this.$options.data.call(this).formData;
        },

        upFileList(e) {
            this.fileList = e;
            console.log(this.fileList);
        },
      
        // 详情
        getDetail(obj) {
            this.loading = true;
            getMachineException(obj).then((res) => {
                if (res.errcode == 0) {
                    var data = res.data.yjQmpMachineException;
                    this.formData = data
                    this.loading = false;
                    this.fileList = res.data.fFilelist;
                    if (this.statusNum == 7) {
                        this.btnShow = false;
                    } else {
                        this.btnShow = true;
                    }
                } else {
                    this.loading = false;
                    this.$message.error(res.msg);
                }
            });
        },
        yj_saveForm(status) {
            this.formData.userId = this.userInfo.userId; //当前登录人id
            this.formData.userName = this.userInfo.realName; //当前登录人名称

            // 0连续新增1新增
            if (this.$refs.publicForm.submitForm()) {
                this.saveForm(this.formData, status);
            } else {
                console.log("error");
            }
        },
        // 保存
        saveForm(data, status) {
            this.loading = true;
            this.formData.typ = this.typs
            this.isLock = true
            updateMachineException(data)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.loading = false;
                        this.visible = false;
                        this.$emit("refreshList", status);
                        this.$message.success("新增成功");
                        this.isLock = false
                    } else {
                        this.loading = false;
                        this.isLock = false
                        this.$message.error(res.data);
                    }
                })
        },
    },
};